<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@3.2.38/dist/vue.global.min.js"></script>
  <style>
    .input-box {
      border: 1px solid black;
      border-radius: 6px;
    }
  </style>
</head>

<body>
  <div id="app">
    <h2>去除空格</h2>
    <input class="input-box" type="text" v-model="msg1">
    <h2>{{filterSpace}}</h2>
    <hr>
    <h2>保留两位小数加元</h2>
    <input class="input-box" type="text" v-model="msg2">
    <h2>{{formatMoney}}</h1>
  </div>
</body>
<script>
  Vue.createApp({
    data() {
      return {
        msg1: '',
        msg2: ''
      }
    },
    computed: {
      filterSpace() {
        return this.msg1.split(' ').join('')
      },
      formatMoney() {
        if (this.msg2 === '') {
          return ''
        } else {
          return Number(this.msg2).toFixed(2) + "元"
        }
      }
    },
    methods: {

    }
  }).mount('#app')
</script>

</html>
